import 'package:easy_refresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:pornhub_app/model/community/community_date_model.dart';
import 'package:pornhub_app/model/community/community_model.dart';
import 'package:pornhub_app/model/mine/share_record_model.dart';

import '../../../../components/base_refresh/base_refresh_page_counter.dart';
import '../../../../http/api/api.dart';
import '../../../components/easy_toast.dart';

class MinePromotionPageController extends GetxController
    with BaseRefreshPageCounter {
  EasyRefreshController refreshController = EasyRefreshController();

  final PagingController<int, ShareRecordModel> pagingControllers =
      PagingController(firstPageKey: 1);

  onRefresh() async {
    resetPage();
    return await getShareRecordList(isRefresh: true);
  }

  onLoad() async {
    incPage();
    return await getShareRecordList();
  }

  getShareRecordList({bool isRefresh = false}) async {
    try {
      if (isRefresh) {
        pagingControllers.refresh();
      }
      final response = await Api.getShareRecordList(page: page, pageSize: 20);
      if (response!.isNotEmpty) {
        pagingControllers.appendPage(response, page);
      } else {
        pagingControllers.appendLastPage([]);
      }
    } catch (_) {}
  }

  onclickItem(int index, CommunityDateModel model) async {
    // if (status == 2) {
    //   // Get.toCommunityDetailNew(dynamicId: model.dynamicId ?? 0);
    // } else if (status == 3) {
    //   List<int> ids = [];
    //   ids.add(model.dynamicId!);
    //   final resp = await Api.delCheckCommunity(dynamicIds: ids);
    //   if (resp) EasyToast.show("删除成功");
    //   onRefresh(status);
    // }
  }
}
